<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="sec" uri="/WEB-INF/tags/shiro.tld"%>
<%@ page import="avicit.platform6.commons.utils.ComUtil"%>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>添加</title>

<base href="<%=ComUtil.getRequestPath(request)%>">
<jsp:include
	page="/avicit/platform6/component/common/EasyUIJsInclude.jsp"></jsp:include>
<jsp:include page="/avicit/im/common/ImUIJSCSSInclude.jsp"></jsp:include>
<link href="avicit/cape/oms/css/icon.css" type="text/css"
	rel="stylesheet">
</head>
<body class="easyui-layout" fit="true">
	<div region="center" border="false" style="overflow: hidden;">
		<form id="formCbbFondsService" method="post">
			<table class="form_commonTable">
				<tr>
					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_odCode">
						<th width="20%"><span class=""></span>全宗号：</th>
						<td width="30%" class="input-readonly"><input type="text"
							validType="length[0,100]" style="" class="easyui-validatebox"
							data-options="required:true" title="全宗号" id="orgCode"
							name="orgCode" value="${OD_CODE }" readonly="readonly" /></td>
					</sec:accesscontrollist>
					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_odName">
						<th width="20%"><span class=""></span>全宗名称：</th>
						<td class="input-readonly"><input type="text"
							validType="length[0,100]" style="" class="easyui-validatebox"
							data-options="required:true" title="全宗名称" id="orgName"
							name="orgName" value="${OD_NAME }" readonly="readonly" /></td>
					</sec:accesscontrollist>
				</tr>
				<tr>
					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_fullsvrType">
						<th width="20%"><span class="remind">*</span>全文服务器类型：</th>
						<td width="30%"><select title="全文服务器类型" editable="false"
							data-options="required:true,panelHeight:'auto',editable:false,onShowPanel:comboboxOnShowPanel"
							class="easyui-combobox" name="fullsvrType" id="fullsvrType"
							style="">
								<c:forEach items="${cbbFullsvrTypeList}" var="fullsvrType">
									<option value="${fullsvrType.lookupCode}">${fullsvrType.lookupName}</option>
								</c:forEach>
						</select></td>
					</sec:accesscontrollist>
					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_svrAddress">
						<th width="20%"><span class="remind">*</span>服务器地址：</th>
						<td><input type="text" validType="length[0,200]" style=""
							class="easyui-validatebox" title="服务器地址" id="svrAddress"
							name="svrAddress" data-options="required:true" /></td>
					</sec:accesscontrollist>
				</tr>
				<tr>
					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_svrPublishPath">
						<th width="20%"><span class="remind">*</span>发布路径：</th>
						<td width="30%"><input type="text" validType="length[0,200]"
							style="" class="easyui-validatebox" title="发布路径"
							id="svrPublishPath" name="svrPublishPath"
							data-options="required:true" /></td>
					</sec:accesscontrollist>
					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_ftpUser">
						<th width="20%"><span class="remind">*</span>FTP用户名：</th>
						<td><input type="text" validType="length[0,50]" style=""
							class="easyui-validatebox" title="FTP用户名" id="ftpUser"
							name="ftpUser" /></td>
					</sec:accesscontrollist>
				</tr>
				<tr>
					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_ftpPassword">
						<th width="20%"><span class="remind">*</span>FTP密码：</th>
						<td width="30%"><input type="password"
							validType="length[0,50]" style="" class="easyui-validatebox"
							title="FTP密码" id="ftpPassword" name="ftpPassword" /></td>
					</sec:accesscontrollist>

					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_isEncrypt">
						<th width="20%"><span class="remind">*</span>是否加密：</th>
						<td><span class="block-box"> <input type="radio"
								class="radiobox" title="是否加密" id="isEncrypt1" name="isEncrypt"
								value="Y" /> <span class="radiobox-text">是</span>
						</span> <span class="block-box"> <input type="radio"
								class="radiobox" title="是否加密" id="isEncrypt2" name="isEncrypt"
								value="N" /> <span class="radiobox-text">否</span>
						</span></td>
					</sec:accesscontrollist>
				</tr>
				<tr>
					<sec:accesscontrollist hasPermission="3"
						domainObject="formdialog_CbbFondsServiceAdd_formCbbFondsService_remark">
						<th width="20%"><span class=""></span>备注：</th>
						<td colspan="3"><textarea style="" type="text"
								class="textareabox" title='备注' name="remark" id="remark"
								validType="length[0,4000]"></textarea></td>
					</sec:accesscontrollist>
				</tr>
			</table>
			<div style="display: none;">
				<label>id</label>
				<div class="inputContainer">
					<input name="id" id="id" required="true" value="${id}" style="" />
				</div>
			</div>

			<div style="display: none;">
				<label>cbbFondsDbId</label>
				<div class="inputContainer">
					<input name="cbbFondsDbId" id="cbbFondsDbId" required="true"
						value="${cbbFondsDbId}" style="" />
				</div>
			</div>
		</form>
	</div>

	<div data-options="region:'south',border:false" style="height: 40px;">
		<div id="toolbar"
			class="datagrid-toolbar datagrid-toolbar-extend foot-formopera">
			<table class="tableForm" border="0" cellspacing="1" width="100%">
				<tr>
					<td align="right"><sec:accesscontrollist hasPermission="3"
							domainObject="formdialog_CbbFondsServiceAdd_button_saveButton">
							<a id="saveButton" class="easyui-linkbutton primary-btn"
								onclick="saveForm();" href="javascript:void(0);">保存</a>
						</sec:accesscontrollist> <sec:accesscontrollist hasPermission="3"
							domainObject="formdialog_CbbFondsServiceAdd_button_resetForm">
							<a id="resetButton" class="easyui-linkbutton"
								onclick="resetForm();" href="javascript:void(0);">重置</a>
						</sec:accesscontrollist> <sec:accesscontrollist hasPermission="3"
							domainObject="formdialog_CbbFondsServiceAdd_button_backForm">
							<a id="backButton" class="easyui-linkbutton"
								onclick="closeWindow();" href="javascript:void(0);">返回</a>
						</sec:accesscontrollist></td>
				</tr>
			</table>
		</div>
	</div>

	<script type="text/javascript">
		$(function() {
			//默认FTP加密框不可用
			document.getElementById("isEncrypt1").disabled = "disabled";
			document.getElementById("isEncrypt2").disabled = "disabled";

			$("#fullsvrType")
					.combo(
							{
								onChange : function(newValue, oldValue) {
									if (newValue == "1") {
										document.getElementById("isEncrypt1").checked = false;
										document.getElementById("isEncrypt2").checked = false;
										document.getElementById("isEncrypt1").disabled = "disabled";
										document.getElementById("isEncrypt2").disabled = "disabled";
										$("#ftpUser").attr("disabled", false);
										$("#ftpPassword").attr("disabled",
												false);
									} else {
										document.getElementById("isEncrypt1").disabled = "";
										document.getElementById("isEncrypt2").disabled = "";
										$("#ftpUser").val("");
										$("#ftpUser").attr("disabled", true);
										$("#ftpPassword").val("");
										$("#ftpPassword")
												.attr("disabled", true);
										document.getElementById("isEncrypt2").checked = true; //默认不加密
									}
								}
							});
		});

		var dialogId = "${dialogId}";

		/**
		 * 获取字符串长度（汉字算两个字符，字母数字算一个）
		 * 
		 * @param str
		 * @returns {Number}
		 */
		function getByteLen(val) {
			var len = 0;
			for ( var i = 0; i < val.length; i++) {
				var a = val.charAt(i);
				if (a.match(/[^\x00-\xff]/ig) != null) {
					len += 2;
				} else {
					len += 1;
				}
			}
			return len;
		}

		//保存
		function saveForm() {
			/***必填字段空格验证 - 2015/11/17 增加 （郭亮）***/
			var svrAddress = $("#svrAddress").val().replace(/(^\s+)|(\s+$)/g,
					"");
			var svrPublishPath = $("#svrPublishPath").val().replace(
					/(^\s+)|(\s+$)/g, "");
			var ftpUser = $("#ftpUser").val().replace(/(^\s+)|(\s+$)/g, "");
			var ftpPassword = $("#ftpPassword").val();
			$("#svrAddress").val(svrAddress);
			$("#svrPublishPath").val(svrPublishPath);
			var fullsvrType = $("#fullsvrType").combobox("getText");
			if (fullsvrType == "FTP") {
				if (ftpUser == "") {
					$("#ftpUser").val("");
					$.messager.alert('提示', 'FTP用户名不能为空！', 'warning');
					return;
				}
				if (ftpPassword == "") {
					$.messager.alert('提示', 'FTP密码不能为空！', 'warning');
					return;
				}
			}
			// 备注长度检验   add by gl 2016-04-28
			var remark = $("#remark").val();
			var remarkLength = getByteLen(remark);
			if (remarkLength > 4000) {
				$.messager.alert('提示', '备注长度不能超过4000位！', 'warning');
				return;
			}
			/***必填字段空格验证 - 2015/11/17 增加 （郭亮）***/
			var validateFlag = $('#formCbbFondsService').form('validate');
			if (validateFlag == false) {
				return;
			}

			var dataVo = $('#formCbbFondsService').serializeArray();
			var dataJson = convertToJson(dataVo);
			dataVo = JSON.stringify(dataJson);

			$
					.ajax({
						url : 'platform/cbbFondsDbController/saveUniqueValidate',
						data : {
							fullsvrType : dataJson.fullsvrType,
							svrAddress : dataJson.svrAddress,
							svrPublishPath : dataJson.svrPublishPath,
							ftpUser : dataJson.ftpUser
						},
						type : 'post',
						dataType : 'json',
						success : function(result) {
							if (result.validate == "1") {
								$.messager.alert('提示', '已存在重复数据！', 'warning');
							} else {
								$
										.ajax({
											url : 'platform/cbbFondsDbController/saveCbbFondsServer',
											data : {
												datas : dataVo,
												type : 'save',
												sysId : '${sysId}'
											},
											type : 'post',
											dataType : 'json',
											success : function(result) {
												parent.freDataGrid();
												closeWindow();
											}
										});
							}
						}
					});
		}

		/**
		 * 关闭弹出窗口
		 */
		function closeWindow() {
			if (parent != null && parent.$('#' + dialogId) != null) {
				parent.$('#' + dialogId).dialog('close');
			}
		}

		/**
		 * 重置表单数据
		 */
		function resetForm(formName, type) {
			$('#formCbbFondsService').form('reset');
		}
		window.onresize = comboboxHidePanel;
	</script>
</body>
</html>